package pl.engine.model.vo.obstacle
{
	import pl.engine.camera.Camera;
	import pl.engine.model.MapGrid;
	import pl.error.InternalError;
	import pl.textures.Textures;

	import starling.display.DisplayObject;
	import starling.display.Image;

	import flash.geom.Point;

	/**
	 * ...
	 * @author Bakudo
	 */
	public class StaticObstacle extends BaseObstacle
	{
		private static var secureFunction:Function;

		public function StaticObstacle( _px:uint, _py:uint, _type:uint, _texture:uint )
		{
			super( _px, _py, _type, _texture );

			if (secureFunction == null) throw new Error( InternalError.CREATION_ERROR );
		}

		override protected function toOverride():void
		{
		}

		public static function factory( _px:uint, _py:uint, _type:uint, _texture:uint ):IBaseObstacle
		{
			secureFunction = function():void
			{
			};
			return new StaticObstacle( Math.floor( _px ), Math.floor( _py ), _type, _texture );
		}

		override public function get display():DisplayObject
		{
			if (_display == null )
			{
				_display = new Image( Textures.getSingleTexture( _texture ).texture );
			}

			return _display ;
		}
		
		override public function cleanView():void
		{
			_display.dispose();	
			_display = null;	
		}

		override public function set x( val:uint ):void
		{
			_x = val;
			_oX = Math.floor( _x / MapGrid.TILE_W );
			var isop:Point = Camera.convertRectToIso( _x, _y );
			_pivotX = Textures.getSingleTexture( _texture ).pivotX;
			_pivotY = Textures.getSingleTexture( _texture ).pivotY;
			_isoX = isop.x - pivotX;
			_isoY = isop.y - pivotY;
		}

		override public function set y( val:uint ):void
		{
			_y = val;
			_oY = Math.floor( _y / MapGrid.TILE_H );
			var isop:Point = Camera.convertRectToIso( _x, _y );
			_pivotX = Textures.getSingleTexture( _texture ).pivotX;
			_pivotY = Textures.getSingleTexture( _texture ).pivotY;
			_isoX = isop.x - pivotX;
			_isoY = isop.y - pivotY;
		}

		override public function get oX():uint
		{
			return _oX;
		}

		override public function get oY():uint
		{
			return _oY;
		}

		override public function get isoX():int
		{
			return _isoX;
		}

		override public function get isoY():int
		{
			return _isoY;
		}
	}
}